package com.eam.action;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.junit.runner.Request;

import com.eam.bean.Asset;
import com.eam.service.AssetService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

/**
 * liubiao
 */
public class AssetAction extends ActionSupport {

	private static final long serialVersionUID = 1L;

	private Asset asset;
	private AssetService assetService;

	public Asset getAsset() {
		return asset;
	}

	public void setAsset(Asset asset) {
		this.asset = asset;
	}

	public AssetService getAssetService() {
		return assetService;
	}

	public void setAssetService(AssetService assetService) {
		this.assetService = assetService;
	}

	public String save() {
		boolean save = assetService.save(asset);
		if (save) {
			query();
			return "save";
		}
		return INPUT;

	}
	
	public String delete(){
		boolean delete=assetService.delete(asset);
		if(delete){
			query();
			return "delete";
		}
		return INPUT;
	}
	
	public String update(){
		boolean update=assetService.update(asset);
		if(update){
			query();
			return "update";
		}
		return INPUT;
	}
	
	public void query() {
		List<Asset> list = assetService.query();
		if (0 != list.size()) {
			ActionContext context = ActionContext.getContext();
			Map<String, Object> session = context.getSession();
			session.put("assetList", list);
		}
	}
	
	public void findByName(){
		System.out.println(asset.getName());
		List<Asset> list=assetService.findByName(asset.getName());
		
		if (0 != list.size()) {
			ActionContext context = ActionContext.getContext();
			Map<String, Object> session = context.getSession();
			session.put("assetList", list);
		}
		
	}

}
